package ru.serverpush.web.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.async.DeferredResult;
import ru.serverpush.web.service.ResultHolder;
import ru.serverpush.web.service.ResultService;

/**
 * Created with IntelliJ IDEA.
 * User: smeshkov
 * Date: 05/11/13
 * Time: 23:25
 * To change this template use File | Settings | File Templates.
 */

@Controller
public class ResultController {

    private static final long TIMEOUT = 50000;

    @RequestMapping(value = "/deferred/listen.json", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    @ResponseBody
    public DeferredResult<ResultHolder> listen() {
        final DeferredResult<ResultHolder> result = new DeferredResult<ResultHolder>( TIMEOUT );
        result.onTimeout(new Runnable() {
            @Override
            public void run() {
                result.setResult(null);
            }
        });
//        if( userManager.isUserAuthorized() ) {
//            service.getUpdate( result, userManager.getProfile().getId() );
//        }
        ResultService.getInstance();
        return result;
    }

}
